<?php
session_start(); 
$firstVisit = false; 
if(!isset($_GET['p']) || !preg_match('/^[a-z]+$/',$_GET['p'])){ $_GET['p'] = 'full';  $firstVisit = true;  }
if($_GET['p'] != 'full' && !file_exists('content/'.$_GET['p'].'.php'))  $_GET['p'] = 'full'; 
$pages = array(
    'index' => 'Dashboard',
    'forms' => 'Forms',
    'table' => 'Table',
    'gallery'=> 'Gallery',
    'notif' => 'Notifications',
    'charts'=> 'Charts',
    'typo'  => 'Typography',
    'icons' => 'Icons',
    'calendar'=>'Calendar'
);
ob_start(); 
?><!DOCTYPE html>
<html>
    <head>
        <title>Your Admin Panel</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

        <!-- Reset all CSS rule -->
        <link rel="stylesheet" href="css/reset.css" />
        
        <!-- Main stylesheed  (EDIT THIS ONE) -->
        <link rel="stylesheet" href="css/style.css" />
        
        <!-- jQuery AND jQueryUI -->
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
        <link rel="stylesheet" href="css/jqueryui/jqueryui.css" />
        
        <!-- jWysiwyg - https://github.com/akzhan/jwysiwyg/ -->
        <link rel="stylesheet" href="js/jwysiwyg/jquery.wysiwyg.old-school.css" />
        <script type="text/javascript" src="js/jwysiwyg/jquery.wysiwyg.js"></script>
        
        
        <!-- Tooltipsy - http://tooltipsy.com/ -->
        <script type="text/javascript" src="js/tooltipsy.min.js"></script>
        
        <!-- iPhone checkboxes - http://awardwinningfjords.com/2009/06/16/iphone-style-checkboxes.html -->
        <script type="text/javascript" src="js/iphone-style-checkboxes.js"></script>
        <script type="text/javascript" src="js/excanvas.js"></script>
        
        <!-- Load zoombox (lightbox effect) - http://www.grafikart.fr/zoombox -->
        <script type="text/javascript" src="js/zoombox/zoombox.js"></script>
        <link rel="stylesheet" href="js/zoombox/zoombox.css" />
        
        <!-- Charts - http://www.filamentgroup.com/lab/update_to_jquery_visualize_accessible_charts_with_html5_from_designing_with/ -->
        <script type="text/javascript" src="js/visualize.jQuery.js"></script>
        
        <!-- Uniform - http://uniformjs.com/ -->
        <script type="text/javascript" src="js/jquery.uniform.min.js"></script>
        
        
        <!-- Main Javascript that do the magic part (EDIT THIS ONE) -->
        <script type="text/javascript" src="js/main.js"></script>

    </head>
    <body>
        
        <?php
        /** 
         * Do not use this content for production, this is done for demo purpose (it adds javascript settings pannel
         */
        require 'content/settings/settings.php';
        ?>
        
        <!--              
                HEAD
                        --> 
        <div id="head">
            <div class="left">
                <a href="" class="button profile"><img src="img/icons/top/huser.png" alt="" /></a>
                Hi, 
                <a href="#">John Doe</a>
                |
                <a href="#">Logout</a>
            </div>
            <div class="right">
                <form action="#" id="search" class="search placeholder">
                    <label>Looking for something ?</label>
                    <input type="text" value="" name="q" class="text"/>
                    <input type="submit" value="rechercher" class="submit"/>
                </form>
            </div>
        </div>
                
                
        <!--            
                SIDEBAR
                         --> 
        <div id="sidebar">
            <ul>
                <li class="nosubmenu">
                    <a href="index.php">
                        <img src="img/icons/menu/inbox.png" alt="" />
                        Dashboard
                    </a>
                </li>
                <li<?php if(!$firstVisit): ?> class="current"<?php endif; ?>><a href="#"><img src="img/icons/menu/layout.png" alt="" /> Elements</a>
                    <ul>
                        <?php foreach($pages as $k=>$v): ?>
                        <li<?php if($k==$_GET['p']): ?> class="current"<?php endif; ?>><a href="index.php?p=<?php echo $k; ?>"><?php echo $v; ?></a></li>
                        <?php endforeach; ?>
                        <li><a href="index.php?p=full">Everything on the same page !</a></li>
                    </ul>
                </li>
                <li><a href="#"><img src="img/icons/menu/brush.png" alt="" /> Another submenu</a>
                    <ul>
                        <li><a href="#">Fake menu #1</a></li>
                        <li><a href="#">Fake menu #2</a></li>
                        <li><a href="#">Fake menu #3</a></li>
                    </ul>
                </li>
                <li class="nosubmenu"><a href="#"><img src="img/icons/menu/lab.png" alt="" /> This button is useless</a></li>
                <li class="nosubmenu"><a href="modal.html" class="zoombox w450 h700"><img src="img/icons/menu/comment.png" alt="" /> Modal box</a></li>
            </ul>


        </div>
                
                
                
                
        <!--            
              CONTENT 
                        --> 
        <div id="content" class="white">
            <?php if($_GET['p'] == 'full'): ?>
                <?php foreach($pages as $k=>$v): ?>
                    <?php require('content/'.$k.'.php'); ?>
                <?php endforeach; ?>
            <?php else: ?>
                <?php require('content/'.$_GET['p'].'.php'); ?>
            <?php endif; ?>
        </div>
        
        
    </body>
</html>
<?php
$content = ob_get_clean();
echo $content;
$content = str_replace('"img/','"../img/',$content);
$content = str_replace('"css/','"../css/',$content);
$content = str_replace('"js/','"../js/',$content);
$content = preg_replace('/index.php\?p=([a-z]+)/','$1.html',$content);
file_put_contents('html/'.$_GET['p'].'.html', $content);
?>